package thread_01;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo34 {
    public static void main(String[] args) {
        ExecutorService service = Executors.newCachedThreadPool();
        for (int i = 0; i < 10000; i++) {
            int finalI = i;
            service.submit(new Runnable() {
                @Override
                public void run() {
//                    I会编译错误，出现变量捕获
//                  System.out.println("hello " + I +Thread.currentThread().getName());
                    System.out.println("hello " + finalI +Thread.currentThread().getName());
                }
            });
        }

        ExecutorService service1 = Executors.newFixedThreadPool(4);
        for (int i = 0; i < 5; i++) {
            service1.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello" + Thread.currentThread().getName());
                }
            });
        }

    }
}
